<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>information_editor</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/normalize/7.0.0/normalize.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/bootstrap.js"></script>
    <script>
        $(function () {
            let id = getQueryString("id");
            let params = {
                id: id
            }
            $.get("http://127.0.0.1:8080/information/update", params, function (result) {
                if (result.status === 200) {
                    let admins = result.data;
                    $("#name").val(admins.name);
                    $("#account").val(admins.account);
                    $("#password").val(admins.password);
                    $("#password2").val(admins.password);
                    $("#phoneNumber").val(admins.phoneNumber);
                    if (admins.jurisdiction=="技术"){
                        $("#r1").attr("checked","checked");
                    }else if (admins.jurisdiction=="设计"){
                        $("#r2").attr("checked","checked");
                    }else if (admins.jurisdiction=="维护"){
                        $("#r3").attr("checked","checked");
                    }else {
                        $("#r4").attr("checked","checked");
                    }
                    $("#remark").val(admins.remark);
                }
            })
            //
            $("#save").click(function () {
                let admins = {}
                admins.id = id;
                admins.name = $("#name").val();
                admins.account=$("#account").val();
                admins.password=$("#password").val();
                admins.phoneNumber=$("#phoneNumber").val();
                admins.jurisdiction=$("input:radio:checked").val();
                admins.remark=$("#remark").html();
                let data={
                    data:JSON.stringify(admins)
                }
                $.post("http://127.0.0.1:8080/information/new", data, function (result) {
                    window.location.href = "classify.html";
                        // "?jurisdiction="+$("input:radio:checked").val();
                })
            });
        })

        function getQueryString(name) {
            let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            let r = window.location.search.substr(1).match(reg);
            return r != null ? unescape(r[2]) : null
        }
    </script>
</head>
<body>
<div class="container-fluid" style="border: solid #ffff00 1px;width: 500px;margin-top: 100px">
    <form>
        <div class="form-group">
            <label for="name">姓名：</label>
            <input id="name" type="text" class="form-control" name="name" placeholder="输入姓名" style="width: 300px">
        </div>
        <div class="form-group">
            <label for="name">账号：</label>
            <input id="account" required type="text" class="form-control" name="account" placeholder="" style="width: 300px">
        </div>
        <div class="form-group">
            <label for="name">密码：</label>
            <input id="password" type="text" class="form-control" name="password" placeholder="密码不能为空" style="width: 300px">
        </div>
        <div class="form-group">
            <label for="name">确认密码：</label>
            <input id="password2" type="text" class="form-control" name="password2" placeholder="" style="width: 300px">
        </div>
        <div class="form-group">
            <label for="name">手机号码</label>
            <input id="phoneNumber" type="number" class="form-control" name="phoneNumber" placeholder="不能为空" style="width: 300px">
        </div>
        <div class="form-group">
            <label for="name">权限</label><br>
            <input type="radio" name="radio" value="技术" id="r1">技术&nbsp&nbsp
            <input type="radio" name="radio" value="设计" id="r2">设计&nbsp&nbsp
            <input type="radio" name="radio" value="维护" id="r3">维护&nbsp&nbsp
            <input type="radio" name="radio" value="管理" id="r4">管理&nbsp&nbsp
        </div>
        <div class="form-group">
            <label for="name">备注</label>
            <textarea cols="35" rows="6" id="remark" name="remark"></textarea>
        </div>
        <div class="form-group">
            <label for="save"></label>
            <input id="save" type="button" class="btn btn-info" value="保存" style="margin-right: 100px">
            <input id="cancel" type="button" class="btn btn-info" value="取消" onclick="history.go(-1)">
        </div>
    </form>
</div>
</body>
</html>